home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #9
/
Amiga Plus CD - 2004 - No. 09.iso
/
amigaplus
/
tools
/
amigaos4_only
/
fracblank
/
source
/
fracgui.c
< prev
next >
Wrap
Text File
|
2004-08-03
|
21KB
|
792 lines
/*
** FracBlank - AmigaDOS 2.04 commodities utility screenblanker
**
** Copyright © 1991-1995 by Olaf `Olsen' Barthel
** All Rights Reserved
**
** Cosmic flame fractal code derived from xlock source code
**
** Copyright © 1988-1991 by Patrick J. Naughton.
*/
/* EditRoutine():
*
* A special string gadget editing routine for key
* combination input.
*/
ULONG EditRoutine(struct Hook *Hook, struct SGWork *Work, ULONG *Msg) {
struct InputEvent Event;
ULONG Qualifier;
UWORD Code;
UBYTE Key[10];
WORD KeyLen;
STRPTR KeyName;
// If the gadget just got activated or the caps lock key
// is active, don't change anything
if (*Msg == SGH_CLICK || (*Msg == SGH_KEY && (Work->IEvent->ie_Qualifier & IEQUALIFIER_CAPSLOCK))) return(TRUE);
else {
// Complain if this is not what we expect to be fun
if(*Msg != SGH_KEY) return(FALSE);
}
// Ditch the qualifier keys
if (Work->IEvent->ie_Code >= 96 && Work->IEvent->ie_Code <= 103) {
Work->Actions &= ~(SGA_USE | SGA_BEEP);
return(TRUE);
}
// Strip all the qualifiers we don't want
Qualifier = Work->IEvent->ie_Qualifier & ~(IEQUALIFIER_REPEAT | IEQUALIFIER_INTERRUPT | IEQUALIFIER_MULTIBROADCAST | IEQUALIFIER_RELATIVEMOUSE);
// Check for raw keys
switch(Work->IEvent->ie_Code) {
case RAWKEY_CURSOR_UP:
case RAWKEY_CURSOR_DOWN:
case RAWKEY_CURSOR_RIGHT:
case RAWKEY_CURSOR_LEFT:
// A cursor key was pressed, check if there
// is probably some special feature involved
if (!(Qualifier & ~(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))) return(TRUE);
// FALLS THROUGH TO:
case RAWKEY_F1:
case RAWKEY_F2:
case RAWKEY_F3:
case RAWKEY_F4:
case RAWKEY_F5:
case RAWKEY_F6:
case RAWKEY_F7:
case RAWKEY_F8:
case RAWKEY_F9:
case RAWKEY_F10:
case RAWKEY_HELP:
// Ok, so this is a raw key event
Code = Work->IEvent->ie_Code;
KeyLen = 0;
break;
default:
// Make a copy of the inputevent and
// clear the qualifier bits
IExec->CopyMem(Work->IEvent,&Event,sizeof(struct InputEvent));
Event.ie_Qualifier = NULL;
Code = 0;
// Translate the event
if ((KeyLen = IKeymap->MapRawKey(&Event,Key,10,NULL)) < 0) KeyLen = 10;
break;
}
// Is the user holding down a single Amiga key?
if (KeyLen && (Qualifier & IEQUALIFIER_RCOMMAND) && !(Qualifier & ~IEQUALIFIER_RCOMMAND)) {
UBYTE Char = IUtility->ToUpper(Key[0]);
// Undo and clear are supported
if (Char == 'Q' || Char == 'X') return(TRUE);
}
// Can we safely continue?
if ((!Code && !KeyLen) || KeyLen > 1 || (!Code && KeyLen && !Key[0])) {
Work->Actions = (Work->Actions & ~SGA_USE) | SGA_BEEP;
return(TRUE);
}
// Take care of special characters
if (KeyLen) {
static struct {
UBYTE Code;
STRPTR Name;
} KeyTable[] = {
'\r', "Return",
'\b', "Backspace",
'\033',"Escape",
' ', "Spacebar",
',', "Comma",
'\177',"Delete",
'\t', "Tab",
0
};
BOOL GotIt = FALSE;
WORD i;
// Carriage return was pressed
if (Key[0] == '\r') {
// This probably ends input
if (!Qualifier) {
Work->Actions = (Work->Actions & ~SGA_BEEP) | SGA_USE | SGA_END;
return(TRUE);
}
else {
// Is this the enter key?
if (Qualifier & IEQUALIFIER_NUMERICPAD) {
KeyName = "Enter";
Qualifier &= ~IEQUALIFIER_NUMERICPAD;
GotIt = TRUE;
}
}
}
// If this is just the tab key, pass it through cleanly
if (Key[0] == '\t' && !(Qualifier & ~(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))) return(TRUE);
// Now check for special characters
Key[0] = IUtility->ToUpper(Key[0]);
if (!GotIt) {
for(i = 0; KeyTable[i].Code; i++) {
if (KeyTable[i].Code == Key[0]) {
KeyName = KeyTable[i].Name;
GotIt = TRUE;
break;
}
}
}
// If no special character is involved,
// use the vanilla character code
if (!GotIt) {
if ((Key[0] > ' ' && Key[0] < 127) || Key[0] >= 160) {
Key[1] = 0;
KeyName = Key;
}
else {
Work->Actions = (Work->Actions & ~SGA_USE) | SGA_BEEP;
return(TRUE);
}
}
}
else {
// Special raw key code table
static struct {
UWORD Code;
STRPTR Name;
} RawTable[] = {
RAWKEY_CURSOR_UP, "Cursor_Up",
RAWKEY_CURSOR_DOWN, "Cursor_Down",
RAWKEY_CURSOR_RIGHT, "Cursor_Right",
RAWKEY_CURSOR_LEFT, "Cursor_Left",
RAWKEY_F1, "F1",
RAWKEY_F2, "F2",
RAWKEY_F3, "F3",
RAWKEY_F4, "F4",
RAWKEY_F5, "F5",
RAWKEY_F6, "F6",
RAWKEY_F7, "F7",
RAWKEY_F8, "F8",
RAWKEY_F9, "F9",
RAWKEY_F10, "F10",
RAWKEY_HELP, "Help",
0
};
WORD i;
// One eventually must match
for(i = 0; RawTable[i].Code; i++) {
if (Code == RawTable[i].Code) {
KeyName = RawTable[i].Name;
break;
}
}
}
// Take care of the qualifiers. Note that we do not distinguish
// between the left and right shift/alt keys
if (Qualifier) {
static struct {
ULONG Qualifier;
STRPTR Name;
} QualifierTable[] = {
IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT, "Shift ",
IEQUALIFIER_LALT | IEQUALIFIER_RALT, "Alt ",
IEQUALIFIER_LCOMMAND, "LAmiga ",
IEQUALIFIER_RCOMMAND, "RAmiga ",
IEQUALIFIER_LEFTBUTTON, "Left_Button ",
IEQUALIFIER_MIDBUTTON, "Middle_Button ",
IEQUALIFIER_RBUTTON, "Right_Button ",
IEQUALIFIER_NUMERICPAD, "Numeric_Pad ",
0
};
WORD i;
// Ok, now start building the string
Work->WorkBuffer[0] = 0;
for(i = 0; QualifierTable[i].Qualifier; i++) {
if (Qualifier & QualifierTable[i].Qualifier) strcat(Work->WorkBuffer,QualifierTable[i].Name);
}
// Add the key itself
strcat(Work->WorkBuffer,KeyName);
// Update the work data
Work->NumChars = strlen(Work->WorkBuffer);
Work->BufferPos = Work->NumChars;
// Finished...
Work->Actions = (Work->Actions & ~(SGA_BEEP | SGA_PREVACTIVE | SGA_NEXTACTIVE | SGA_END)) | SGA_REDISPLAY | SGA_USE;
}
else Work->Actions &= ~(SGA_USE | SGA_BEEP);
return(TRUE);
}
/* UpdateModeString():
*
* This routine builds the screen mode and screen depth string
* for the user interface.
*/
VOID
UpdateModeString()
{
WORD Len;
if (!GetModeName(DisplayID,DisplayModeBuffer))
strcpy(DisplayModeBuffer,"«Default screen mode»");
Len = strlen(DisplayModeBuffer);
if (Depth)
SPrintf(&DisplayModeBuffer[Len],", %ld colours",1L << Depth);
else
strcpy(&DisplayModeBuffer[Len],", «Maximum depth»");
}
/* ShowTime(struct Gadget *SomeGadget,WORD Level):
*
* Gadtools support routine, displays the timeouts.
*/
LONG __saveds __stdargs
ShowTime(struct Gadget *SomeGadget,WORD Level)
{
STATIC UBYTE Buffer[30];
if (Level)
SPrintf(Buffer,"%2ld:%02ld min.",Level / 60,Level % 60);
else
SPrintf(Buffer,"«Off»");
return((LONG)Buffer);
}
/* ShowDots(struct Gadget *SomeGadget,WORD Level):
*
* Cheap trick; multiply the number of dots by 100.
*/
LONG __saveds __stdargs
ShowDots(struct Gadget *SomeGadget,WORD Level)
{
return((LONG)Level * 100);
}
/* ShutdownWindow():
*
* Closes the control panel.
*/
VOID
ShutdownWindow()
{
if (Handle)
{
LT_DeleteHandle(Handle);
Handle = NULL;
Window = NULL;
CloseLibrary(GTLayoutBase);
GTLayoutBase = NULL;
}
}
/* SetupWindow():
*
* Creates the control panel and disables the screen
* blanker.
*/
BOOL
SetupWindow()
{
if (Handle)
{
LT_ShowWindow(Handle,TRUE);
return(TRUE);
}
else
{
if (!(GTLayoutBase = SafeOpenLibrary("PROGDIR:gtlayout.library",9)))
GTLayoutBase = SafeOpenLibrary("gtlayout.library",9);
if (GTLayoutBase)
{
if (Handle = LT_CreateHandleTagList(NULL,NULL))
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_LabelText, "Fractal screen blanker",
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
STATIC STRPTR Copyright[] =
{
"Copyright © 1991-1995",
"by Olaf `Olsen' Barthel",
"All Rights Reserved",
NULL
};
LT_New(Handle,
LA_Type, BOX_KIND,
LABX_Lines, Copyright,
LABX_AlignText, ALIGNTEXT_CENTERED,
LA_DrawBox, FALSE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_LabelText, "Controls",
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
STATIC STRPTR FractalTypes[] =
{
"Real plane",
"Cosmic flames",
"« Random »",
NULL
};
STATIC STRPTR ColourModes[] =
{
"Cycling",
"Static",
NULL
};
LT_New(Handle,
LA_Type, SLIDER_KIND,
LA_LabelText, "Screen timeout",
GTSL_Min, 0,
GTSL_Max, 30 * 60,
GTSL_LevelFormat, "%s",
GTSL_DispFunc, ShowTime,
LA_ULONG, &ScreenTimeout,
LA_Chars, 20,
TAG_DONE);
LT_New(Handle,
LA_Type, SLIDER_KIND,
LA_LabelText, "Pattern timeout",
GTSL_Min, 0,
GTSL_Max, 30 * 60,
GTSL_LevelFormat, "%s",
GTSL_DispFunc, ShowTime,
LA_ULONG, &PatternTimeout,
TAG_DONE);
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
EditHook.h_Entry = (HOOKFUNC)EditRoutine;
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelText, "Hot key",
GTST_MaxChars, 255,
GTST_String, HotkeyBuffer,
GTST_EditHook, &EditHook,
LA_ID, GAD_HOTKEY,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelText, "Blank screen",
GTST_MaxChars, 255,
GTST_String, BlankScreenBuffer,
GTST_EditHook, &EditHook,
LA_ID, GAD_BLANKSCREEN,
TAG_DONE);
if (DataTypesBase)
{
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelText, "Save screen to clipboard",
GTST_MaxChars, 255,
GTST_String, SaveScreenBuffer,
GTST_EditHook, &EditHook,
LA_ID, GAD_SAVESCREEN,
TAG_DONE);
}
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
UpdateModeString();
LT_New(Handle,
LA_Type, TEXT_KIND,
LA_LabelText, "Display mode",
LA_ID, GAD_MODE,
GTTX_Text, DisplayModeBuffer,
GTTX_Border, TRUE,
LATX_Picker, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelText, "Colour mode",
GTCY_Labels, ColourModes,
LA_UBYTE, &ColourMode,
TAG_DONE);
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelText, "Fractal type",
GTCY_Labels, FractalTypes,
LA_UBYTE, &FractalType,
TAG_DONE);
LT_New(Handle,
LA_Type, SLIDER_KIND,
LA_LabelText, "Maximum recursion level",
GTSL_Min, 10,
GTSL_Max, 100,
GTSL_LevelFormat, "%ld",
LA_ULONG, &MaxRecursionLevel,
TAG_DONE);
LT_New(Handle,
LA_Type, SLIDER_KIND,
LA_LabelText, "Maximum dots",
GTSL_Min, 10,
GTSL_Max, 1000,
GTSL_LevelFormat, "%lD",
GTSL_DispFunc, ShowDots,
LA_ULONG, &MaxFlamePoints,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
LAXB_FullSize, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
LAGR_Spread, TRUE,
LAGR_SameSize, TRUE,
TAG_DONE);
{
if (!MainProcess->pr_CLI)
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelText, "Save",
LABT_ExtraFat, TRUE,
LA_ID, GAD_SAVE,
LA_Chars, 8,
TAG_DONE);
}
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelText, "Hide",
LABT_ReturnKey, TRUE,
LABT_ExtraFat, TRUE,
LA_ID, GAD_HIDE,
LA_Chars, 8,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelText, "Quit",
LA_ID, GAD_QUIT,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
if (Window = LT_Build(Handle,
LAWN_IDCMP, IDCMP_CLOSEWINDOW,
LAWN_BelowMouse, TRUE,
LAWN_SmartZoom, TRUE,
LAWN_TitleText, &VersTag[7],
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_DragBar, TRUE,
WA_RMBTrap, TRUE,
WA_Activate, TRUE,
TAG_DONE))
{
ResetRequest = TRUE;
return(TRUE);
}
LT_DeleteHandle(Handle);
Handle = NULL;
}
ReportError(NULL,NULL,ERR_NoWindow);
CloseLibrary(GTLayoutBase);
GTLayoutBase = NULL;
}
else
ReportError(NULL,NULL,ERR_NoGTLayout);
return(FALSE);
}
}
BOOL HandleWindowInput(ULONG SignalSet) {
if (SignalSet & SIG_WINDOW) {
struct IntuiMessage *IMsg;
BOOL Hide = FALSE;
ULONG MsgClass;
struct Gadget *MsgGadget;
ULONG LocalID,LocalDepth;
IX Expression;
BOOL NewKeys;
STRPTR String;
LONG Error;
struct IBox Box;
while(IMsg = LT_GetIMsg(Handle))
{
MsgClass = IMsg->Class;
MsgGadget = (struct Gadget *)IMsg->IAddress;
LT_ReplyIMsg(IMsg);
switch(MsgClass)
{
case IDCMP_CLOSEWINDOW:
Hide = TRUE;
break;
case IDCMP_GADGETUP:
switch(MsgGadget->GadgetID)
{
case GAD_QUIT:
Done = TRUE;
break;
// Make sure that the key
// codes are correct
case GAD_BLANKSCREEN:
case GAD_SAVESCREEN:
case GAD_HOTKEY:
if (ParseIX(LT_GetString(Handle,MsgGadget->GadgetID),&Expression))
{
DisplayBeep(Window->WScreen);
LT_Activate(Handle,MsgGadget->GadgetID);
}
break;
case GAD_HIDE:
case GAD_SAVE:
LT_LockWindow(Window);
// Update the Commodities
// interface only if the
// key assignments have
// changed
NewKeys = FALSE;
String = LT_GetString(Handle,GAD_HOTKEY);
if (!ParseIX(String,&Expression))
{
IX OldExpression;
ParseIX(HotkeyBuffer,&OldExpression);
if (memcmp(&Expression,&OldExpression,sizeof(IX)))
{
SpecialQualifier = SubQualifier(HotkeyBuffer,SpecialQualifier);
strcpy(HotkeyBuffer,String);
SpecialQualifier = AddQualifier(HotkeyBuffer,SpecialQualifier);
NewKeys = TRUE;
}
}
String = LT_GetString(Handle,GAD_BLANKSCREEN);
if (!ParseIX(String,&Expression))
{
IX OldExpression;
ParseIX(BlankScreenBuffer,&OldExpression);
if (memcmp(&Expression,&OldExpression,sizeof(IX)))
{
SpecialQualifier = SubQualifier(BlankScreenBuffer,SpecialQualifier);
strcpy(BlankScreenBuffer,String);
SpecialQualifier = AddQualifier(BlankScreenBuffer,SpecialQualifier);
NewKeys = TRUE;
}
}
String = LT_GetString(Handle,GAD_SAVESCREEN);
if (!ParseIX(String,&Expression))
{
IX OldExpression;
ParseIX(SaveScreenBuffer,&OldExpression);
if (memcmp(&Expression,&OldExpression,sizeof(IX)))
{
SpecialQualifier = SubQualifier(SaveScreenBuffer,SpecialQualifier);
strcpy(SaveScreenBuffer,String);
SpecialQualifier = AddQualifier(SaveScreenBuffer,SpecialQualifier);
NewKeys = TRUE;
}
}
LT_UnlockWindow(Window);
if (NewKeys)
{
if (Error = SetupCx())
{
if (Error != ERR_Duplicate)
ReportError(Window,NULL,Error);
CloseAll(RETURN_FAIL);
}
}
if (MsgGadget->GadgetID == GAD_HIDE)
Hide = TRUE;
else
SaveOptions(argv);
break;
}
break;
// Pick a new display mode
case IDCMP_IDCMPUPDATE:
if (DisplayID == INVALID_ID)
LocalID = GetVPModeID(&Window->WScreen->ViewPort);
else
LocalID = DisplayID;
if (Depth)
LocalDepth = Depth;
else
{
struct DimensionInfo DimensionInfo;
if (GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(DimensionInfo),DTAG_DIMS,LocalID))
LocalDepth = DimensionInfo.MaxDepth;
else
LocalDepth = 2;
}
if (ScreenModeRequest->sm_UserData && !ResetRequest)
CopyMem(&ScreenModeRequest->sm_LeftEdge,&Box,sizeof(struct IBox));
else
{
CopyMem(&Window->LeftEdge,&Box,sizeof(struct IBox));
Box.Top += Window->BorderTop;
Box.Height -= Window->BorderTop;
}
if (AslRequestTags(ScreenModeRequest,
ASLSM_Window, Window,
ASLSM_SleepWindow, TRUE,
ASLSM_InitialDisplayID, LocalID,
ASLSM_InitialDisplayDepth, LocalDepth,
ASLSM_UserData, TRUE,
ASLSM_InitialLeftEdge, Box.Left,
ASLSM_InitialTopEdge, Box.Top,
ASLSM_InitialWidth, Box.Width,
ASLSM_InitialHeight, Box.Height,
TAG_DONE))
{
ResetRequest = FALSE;
DisplayID = ScreenModeRequest->sm_DisplayID;
Depth = ScreenModeRequest->sm_DisplayDepth;
UpdateModeString();
LT_SetAttributes(Handle,GAD_MODE,
GTTX_Text, DisplayModeBuffer,
TAG_DONE);
}
else
ResetRequest = TRUE;
break;
}
}
if (Hide)
ShutdownWindow();
}
}